﻿using System;
using System.Windows;
using GameLogic.Controls;

namespace GameLogic.Logic
{
    // Change selected game properties when this action is fired
    public class ChangeGamePropertiesAction : GameTriggerAction<FrameworkElement>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
        }

        #region Dependency Properties

        public bool ChangeLivesOnAction
        {
            get { return (bool)this.GetValue(ChangeLivesOnActionProperty); }
            set { this.SetValue(ChangeLivesOnActionProperty, value); }
        }

        public static readonly DependencyProperty ChangeLivesOnActionProperty =
            DependencyProperty.Register(
                "ChangeLivesOnAction",
                typeof(bool),
                typeof(ChangeGamePropertiesAction),
                null);

        public bool ChangeScoresOnAction
        {
            get { return (bool)this.GetValue(ChangeScoresOnActionProperty); }
            set { this.SetValue(ChangeScoresOnActionProperty, value); }
        }

        public static readonly DependencyProperty ChangeScoresOnActionProperty =
            DependencyProperty.Register(
                "ChangeScoresOnAction",
                typeof(bool),
                typeof(ChangeGamePropertiesAction),
                null);

        public int LivesIncrementValue
        {
            get { return (int)this.GetValue(LivesIncrementValueProperty); }
            set { this.SetValue(LivesIncrementValueProperty, value); }
        }

        public static readonly DependencyProperty LivesIncrementValueProperty =
            DependencyProperty.Register(
                "LivesIncrementValue",
                typeof(int),
                typeof(ChangeGamePropertiesAction),
                null);

        public int ScoresIncrementValue
        {
            get { return (int)this.GetValue(ScoresIncrementValueProperty); }
            set { this.SetValue(ScoresIncrementValueProperty, value); }
        }

        public static readonly DependencyProperty ScoresIncrementValueProperty =
            DependencyProperty.Register(
                "ScoresIncrementValue",
                typeof(int),
                typeof(ChangeGamePropertiesAction),
                null);

        #endregion

        protected override void Invoke(object parameter)
        {
            if (this.ChangeLivesOnAction)
            {
                GameContainer.Game.OnLivesChanged(this.LivesIncrementValue);
            }

            if (this.ChangeScoresOnAction)
            {
                GameContainer.Game.OnScoresChanged(this.ScoresIncrementValue);
            }
        }
    }
}